﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using SNSpirit.Service.Access;

namespace SNSpirit.Service.Web
{
    public class WebClientAccessor : WebClient
    {
        public IWebAccessor Accessor { get; set; }

        protected override WebRequest GetWebRequest(Uri address)
        {
            if (this.Accessor != null)
            {
                return this.Accessor.RequestProcess(base.GetWebRequest(address));
            }
            else
            {
                return base.GetWebRequest(address);
            }
        }

        protected override WebResponse GetWebResponse(WebRequest request)
        {
            if (this.Accessor != null)
            {
                return this.Accessor.ResponseProcess(base.GetWebResponse(request));
            }
            else
            {
                return base.GetWebResponse(request);
            }
        }

        protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
        {
            if (this.Accessor != null)
            {
                return this.Accessor.ResponseProcess(base.GetWebResponse(request, result));
            }
            else
            {
                return base.GetWebResponse(request, result);
            }
        }
    }
}